<script setup lang='ts'>
  import { onMounted, reactive, ref } from 'vue';
  import { statisticsApi } from '@/api/controller';
  import { Toastloading, ToastSuccess, ToastWarning } from '@/utils/public';
  import Pagination from "@/components/Pagination/index.vue";
  import serachUserid from '@/components/serachUserid/index.vue';
  import reviewForm from './reviewForm.vue';
  const reviewFormRef = ref()
  const action = reactive({
    total:0,
    list:[] as any[],
  })
  const statusTypeList = [
    {type:-1,text:'全部'},
    {type:0,text:'未审核'},
    {type:1,text:'审核通过'},
    {type:2,text:'审核驳回'},
  ]
  const dataType = [
    {type:1,text:'自定义活动'},
  ]
  const listQuery = reactive({
    user_id:'',
    to_user_id:'',
    page: 1,
    limit: 20,
    b_status:0
  })
  const handleFilter = ()=>{
    listQuery.page = 1
    getList()
  }
  const resetQuery = ()=>{
    Object.assign(listQuery,{
      user_id:'',
      status:'',
      page: 1,
      limit: 20,
    })
    getList()
  }
  const handleAudit = (row:any = {},b_status=0)=>{
    if(!b_status) return ToastWarning('status Null')
    reviewFormRef.value.openDialog({...row,b_status})
  }
  const getList = async()=> {
    const loading = Toastloading()
    const res = await statisticsApi.sdj2023LybList(listQuery)
    loading.close()
    const { data=[], total=0 } = res.data
    action.list = data
    action.total = total
  }
  onMounted(()=>{
    getList()
  })
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <div class="label">发送人UUID：</div>
          <serachUserid v-model:user_id="listQuery.user_id" />
        </div>
        <div class="labelItem">
          <div class="label">接受人UUID：</div>
          <serachUserid v-model:user_id="listQuery.to_user_id" />
        </div>
        <div class="labelItem">
          <div class="label">审核状态：</div>
          <el-select v-model="listQuery.b_status" clearable placeholder="请选择审核状态">
            <el-option v-for="item in statusTypeList" :label="item.text" :value="item.type" />
          </el-select>
        </div>
        <div class="labelItem">
          <el-button type="primary" @click="handleFilter">查询</el-button>
          <el-button type="primary" @click="resetQuery">重置</el-button>
        </div>
      </div>
    </div>
    <el-table
      class="xm-main xm-TableCenter"
      :data="action.list"
      border>
      <el-table-column min-width="120" prop="id" label="ID" />
      <el-table-column min-width="120" prop="user_id" label="发送人ID" />
      <el-table-column min-width="120" prop="userName" label="发送人昵称" />
      <el-table-column min-width="120" prop="to_user_id" label="接收人ID" />
      <el-table-column min-width="120" prop="toUserName" label="接收人昵称" />
      <el-table-column min-width="120" prop="base_content" label="初始留言内容" />
      <el-table-column min-width="120" prop="show_content" label="屏蔽敏感词后展示内容" />
      <el-table-column min-width="120" prop="diamand_num" label="留言消耗钻石数" />
      <el-table-column min-width="120" prop="a_status" label="机审状态">
        <template #default="scope">
          {{ ['未审核','已审核'][scope.row.a_status] }}
        </template>
      </el-table-column>
      <el-table-column min-width="120" prop="b_status" label="人工审状态">
        <template #default="scope">
          {{ statusTypeList.find(res=> res.type == scope.row.b_status)?.text || scope.row.b_status }}
        </template>
      </el-table-column>
      <el-table-column min-width="120" prop="data_type" label="类型">
        <template #default="scope">
          {{ dataType.find(res=>res.type == scope.row.data_type)?.text || scope.row.data_type }}
        </template>
      </el-table-column>
      <el-table-column min-width="120" prop="remind" label="备注" />
      <el-table-column min-width="120" prop="created_at" label="创建时间" />
      <el-table-column width="180" fixed=right label="操作">
        <template #default="scope">
          <template v-if="scope.row.b_status == 0">
            <el-button type="primary" @click="handleAudit(scope.row,1)">通过</el-button>
            <el-button type="danger" @click="handleAudit(scope.row,2)">驳回</el-button>
          </template>
        </template>
      </el-table-column>
    </el-table>
    <Pagination v-show="action.total > 0" :total="action.total" v-model:page="listQuery.page"
      v-model:limit="listQuery.limit" @pagination="getList" />
    <reviewForm ref="reviewFormRef" @update-list="getList" />
  </div>
</template>